package com.atguigu.datasource2;

import com.atguigu.bean.WaterSensor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Flink01_DataSourceFromCollection {
    public static void main(String[] args) {
        //从集合中读取元素
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",10000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
        env.setParallelism(2);

        //从集合中读取元数据
        //创建集合
        List<WaterSensor> source = Arrays.asList(new WaterSensor("sensor_1", 1633792000L, 10),
                new WaterSensor("sensor_2", 1633794000L, 50),
                new WaterSensor("sensor_3", 1633796000L, 40)
        );
        DataStreamSource<WaterSensor> ds = env.fromCollection(source);
        ds.print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
